package com.gitee.aurora.client;

import org.springframework.beans.factory.annotation.Value;

import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import java.net.URI;

/**
 * author: jiangfuxiao
 * Date:2022/9/7 10:59
 */
@ClientEndpoint
public class WebSocketClent {

    @Value("${deptCode}")
    private String deptCode;
    @Value("${webSocketUrl}")
    private String webSocketUrl;

    public WebSocketClent() {
    }

    public void sendMessage(String str) throws Exception {

        Session session = ContainerProvider.getWebSocketContainer().connectToServer(this,new URI(webSocketUrl+deptCode));
        session.getBasicRemote().sendText(str);
    }
}
